//
//  PayController.m
//  village_ios
//
//  Created by mac on 2019/8/11.
//  Copyright © 2019 com.sw.village. All rights reserved.
//

#import "PayController.h"
#import "BaseTipController.h"
@interface PayController ()
@property (weak, nonatomic) IBOutlet UIButton *payButton;

@end

@implementation PayController

- (void)viewDidLoad {
    [super viewDidLoad];

    //health
    if (self.healthPayOrder) {

        NSString *payTitle = [NSString stringWithFormat:@"微信支付%@元",self.healthPayOrder.total];
        [self.payButton setTitle:payTitle forState:0];

    }else if (self.partyPayOrder) {
        
        NSString *payTitle = [NSString stringWithFormat:@"微信支付%@元",self.partyPayOrder.total];
        [self.payButton setTitle:payTitle forState:0];
    }
}


- (IBAction)toPay:(id)sender {
    
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (self.healthPayOrder) {
        [params addEntriesFromDictionary:@{@"type":@(1)}];
    }else if (self.partyPayOrder) {
        [params addEntriesFromDictionary:@{@"type":@(2)}];
    }
    //具体参数
    
    
    [SYProgressHUD show];
    [APIManager requestWithUrlString:@"api/healthPay/addItem" params:params method:@"GET" success:^(id response) {
        
        [SYProgressHUD hide];
        
        //提示
        [BaseTipController presentNaviController:self success:^{
            [SYProgressHUD show];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [SYProgressHUD hide];
                if (self.paySuccess) {
                    self.paySuccess();
                }
                [self.navigationController popViewControllerAnimated:YES];
            });
        }];
        
        
    } failure:^(NSError *error) {
        [SYProgressHUD showInfoText:@"支付失败"];
    }];
}
@end
